<template>
  <view class="container" v-if="cart.length !== 0">
    <!-- 收货地址 -->
    <my-address></my-address>
    <!-- 头部标志 -->
    <view class="top-title">
    <uni-icons type="shop" size="18"></uni-icons>
    <div class="text">购物车</div>
    </view>
    <!-- 购物车 -->
    <div class="cart-list">
      <uni-swipe-action>
          <view class="cart-item" v-for="(item,index) in cart" :key="index">
        <uni-swipe-action-item :right-options="options" @click="onClick(item)" >
            <my-goods 
            :item="item" 
            :isShowRadio="true"
            :numBoxShow="true"
            @radio-change="radioChange"
            @numBox-change='numBoxChange'
            ></my-goods>
        </uni-swipe-action-item>
          </view>
      </uni-swipe-action>
    </div>
    <!-- 自定义结算组件 -->
    <my-settle></my-settle>
  </view>
  <view v-else class="cart-empty">
    <view class="pic">
      <image src="/static/cart_empty@2x.png" mode="aspectFit"></image>
    </view>
    <view class="text">
      空空如也~
    </view>
  </view>
</template>

<script>
  import  tabbarBadge  from '@/mixins/tabbar-badge.js'
  import { mapState,mapMutations } from 'vuex'
  export default {
    mixins:[tabbarBadge],
    data() {
      return {
         options:[
                    {
                    text: '删除',
                    style: {
                        backgroundColor: '#C00000'
                    }
                }
              ]
      }
    },
    computed:{
      ...mapState('cart',['cart'])
    },
    methods:{
      ...mapMutations('cart',['UPDATECART','DELETECART']),
      // 点击单选框
      radioChange(e) {
        // console.log(e);
       this.UPDATECART(e)
      },
      // 数量发生变化
      numBoxChange(e) {
        // console.log(e);
         this.UPDATECART(e)
      },
      // 点击删除操作
      onClick(goods){
        // console.log(goods);
        this.DELETECART(goods)
      },

    }

  }
</script>

<style scoped lang="scss">
  .container {
    background-color: #fff;
    padding-bottom: 50px;
  }
.top-title {
  display: flex;
  width: 100%;
  height: 40px;
  line-height: 40px;
  background-color: #fff;
  margin: 0rpx 10rpx;
  border-bottom: 1px solid #efefef;
  .text {
    padding-left: 15rpx;
    font-size: 14px;
  }
}
.cart-list {
  background-color: #fff;
}
.cart-empty {
  display: flex;
  height: 80vh;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  .pic {
    width: 80px;
    height: 80px;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .text {
    margin-top: 30rpx;
    color: #999;
    font-size: 14px;
  }
}
</style>
